package com.AuthServer.job;

import com.AuthServer.pojo.entity.Secret;
import com.AuthServer.service.SecretService;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.UUID;

@Component
public class SecretUpdateJob implements Job {

    @Autowired
    @Qualifier("default")
    private RedisTemplate<String,Object> template;
    @Autowired
    private SecretService secretService;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) {
        String secret = UUID.randomUUID().toString();
        Timestamp updateTime = Timestamp.valueOf(LocalDateTime.now());
        secretService.updateById(new Secret(1,secret,updateTime));
        template.delete("key_secret");
    }
}
